package com.easylinkin.linkappapi.lobar.controller.app;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.lobar.dto.CountWarningDTO;
import com.easylinkin.linkappapi.lobar.dto.WarningDTO;
import com.easylinkin.linkappapi.lobar.entity.Warning;
import com.easylinkin.linkappapi.lobar.service.WarningService;
import com.easylinkin.linkappapi.lobar.vo.WarningVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

/**
 * @author xiaoyang
 * @version 1.0
 * @date 2022/07/22
 * @description app端告警中心
 */
@RestController
@RequestMapping("appWarning")
@Api(tags = "app端告警中心")
public class AppWarningController {

  @Autowired
  private WarningService warningService;

  /**
   * 根据条件，分页(不分页)查询所有预警
   * @param requestModel
   * @return
   */
  @PostMapping("queryWarning")
  @ApiOperation("根据条件，分页(不分页)查询所有预警")
  public RestMessage queryWarning(@RequestBody RequestModel<WarningDTO> requestModel){
    Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams 不能为空");
    Assert.notNull(requestModel.getPage(), "page 不能为空");
    IPage<Warning> record = warningService.queryWarning(requestModel);
    return RestBuilders.successBuilder().data(record).build();
  }

  /**
   * 处理告警
   * @param warning
   * @return
   */
  @PostMapping("handleWarning")
  @ApiOperation("处理告警")
  public RestMessage handleWarning(@RequestBody Warning warning){
    Assert.notNull(warning, "warning 不能为空");
    Assert.notNull(warning.getId(), "id 不能为空");
    Assert.notNull(warning.getWarningType(), "warningType 不能为空");
    Assert.notNull(warning.getHandleRemark(), "handleRemark 不能为空");
    return warningService.handleWarning(warning);
  }

  /**
   * 根据条件，统计预警处理状态
   * @param warningDTO
   * @return
   */
  @PostMapping("countWarning")
  @ApiOperation("根据条件，统计预警处理状态")
  public RestMessage countWarning(@RequestBody WarningDTO warningDTO){
    Assert.notNull(warningDTO, "customQueryParams 不能为空");
    CountWarningDTO record = warningService.countWarning(warningDTO);
    return RestBuilders.successBuilder().data(record).build();
  }

  /**
   * 批量处理告警
   *
   * @param warningVo 预警入参vo
   * @return 统一出参
   */
  @PostMapping("/warningBatchOperate")
  @ApiOperation("批量处理告警")
  public RestMessage warningBatchOperate(@RequestBody WarningVo warningVo) {
    Assert.notNull(warningVo.getBatchType(), "批量操作类型不能为空");
    Assert.notNull(warningVo.getWarningType(), "warningType 不能为空");
    //Assert.notNull(warningVo.getHandleRemark(), "handleRemark 不能为空");
    return warningService.warningBatchOperate(warningVo);
  }

}
